CUR_DIR=$(shell pwd)
ITRUSTEE_BUILD_PATH=${CUR_DIR}/../../../..
include ./config.mk
include ${ITRUSTEE_BUILD_PATH}/build/mk/common.mk

SRC += $(wildcard src/se_api/*.c) \
	   $(wildcard src/se_ipc_client/*.c) \
	   $(wildcard src/secure_channel/*.c)

# set header directory
INCLUDEDIR += -I./include
INCLUDEDIR += -I./libse/src/se_service
INCLUDEDIR += -I./libse/src/secure_channel

# set target
COBJS := $(SRC:%.c=%.o)
TARGET = $(COBJS)

sec_binary:combine
	python3 -B ${SIGNTOOL_DIR}/signtool_v3.py ${CUR_DIR} ${CUR_DIR} --privateCfg ${SIGNTOOL_DIR}/config_cbg.ini

# attention: must add ta_entry_check.sh as below to check whether ta is valid
combine: $(TARGET)
	$(LD) $(LDFLAGS) $(TARGET) $(EXTRAO) -o libcombine.so
	bash $(ITRUSTEE_BUILD_PATH)/build/tools/ta_entry_check.sh $(READELF) $(shell pwd)/libcombine.so n y $(TARGET_IS_ARM64)

src/%.o: ./src/%.c
	$(CC) $(CFLAGS)  $(INCLUDEDIR) -c $< -o $@

%.o: %.c
	$(CC) $(CFLAGS)  $(INCLUDEDIR) -c $< -o $@

clean:
	rm -f $(COBJS) *.so *.sec
